gRPC 除了前面基本範例的一元(Unary call) 還有以下三種 Stream 方式
在 .proto
檔裡面做下面的宣告,就可以做上面三種 Stream 的設定
以下範例來自微軟官網
syntax = "proto3";
service ExampleService {
// 伺服器串流(Server streaming)
rpc StreamingFromServer (ExampleRequest) returns (stream ExampleResponse);
// 用戶端串流(Client streaming)
rpc StreamingFromClient (stream ExampleRequest) returns (ExampleResponse);
// 雙向串流(Bi-directional streaming)
rpc StreamingBothWays (stream ExampleRequest) returns (stream ExampleResponse);
}
設定的部分還蠻好理解的,以上就是在 Server 端的 .proto
設定,後面接續介紹相關的 Server/Client 程式